/**
 * 
 */
package mapreduce4j;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

/**
 * The job to run
 * @author tim
 */
public class Job {
	protected String name;
	protected Configuration config;
	protected Class<? extends Mapper> mapperClass;
	protected Class<? extends Reducer> reducerClass;
	protected Class<? extends InputFormat> inputFormat;
	
	// the main job input files
	protected List<File> inputFiles = new ArrayList<File>();
	
	// the job output file
	protected File outputFile;
	
	/**
	 * @param config for the job
	 * @param name Used in logging
	 */
	public Job(Configuration config, String name) {
		this.name = name;
		this.config = config;
	}
	
	/**
	 * @param blockUntilFinished should this run in the same thread or submit and return?
	 * @return true if no errors (always)
	 */
	public boolean waitForCompletion(boolean blockUntilFinished) {
		JobExecutor executor = new JobExecutor();
		executor.execute(this, blockUntilFinished);
		return true;
	}
	
	/**
	 * @param input To add to the input files for the job
	 */
	public void addInput(File input) {
		inputFiles.add(input);
	}
	
	// getters and setters follow
	public String getName() {
		return name;
	}
	public Configuration getConfiguration() {
		return config;
	}
	public void setMapperClass(Class<? extends Mapper> mapperClass) {
		this.mapperClass = mapperClass;
	}
	public Class<? extends Mapper> getMapperClass() {
		return mapperClass;
	}
	public void setOutputFile(File output) {
		this.outputFile = output;
	}
	public List<File> getInputFiles() {
		return inputFiles;
	}
	public Class<? extends InputFormat> getInputFormat() {
		return inputFormat;
	}
	public void setInputFormat(Class<? extends InputFormat> inputFormat) {
		this.inputFormat = inputFormat;
	}

	public Class<? extends Reducer> getReducerClass() {
		return reducerClass;
	}
	public void setReducerClass(Class<? extends Reducer> reducerClass) {
		this.reducerClass = reducerClass;
	}
}
